package org.hh.jga.util;

/**
 * array utils provide 
 * swap, en/de capsulate functions
 * 
 * @author Hong Hong
 *
 */
public class ArrayUtil {
	public static void swap(int[] array, int left, int right) {
		int tmp = array[left];
		array[left] = array[right];
		array[right] = tmp;
	}
	public static void swap(long[] array, int left, int right) {
		long tmp = array[left];
		array[left] = array[right];
		array[right] = tmp;
	}
	public static void swap(short[] array, int left, int right) {
		short tmp = array[left];
		array[left] = array[right];
		array[right] = tmp;
	}
	public static void swap(char[] array, int left, int right) {
		char tmp = array[left];
		array[left] = array[right];
		array[right] = tmp;
	}
	public static void swap(byte[] array, int left, int right) {
		byte tmp = array[left];
		array[left] = array[right];
		array[right] = tmp;
	}
	public static void swap(boolean[] array, int left, int right) {
		boolean tmp = array[left];
		array[left] = array[right];
		array[right] = tmp;
	}
	public static void swap(float[] array, int left, int right) {
		float tmp = array[left];
		array[left] = array[right];
		array[right] = tmp;
	}
	public static void swap(double[] array, int left, int right) {
		double tmp = array[left];
		array[left] = array[right];
		array[right] = tmp;
	}
	public static <T> void swap(T[] array, int left, int right) {
		T tmp = array[left];
		array[left] = array[right];
		array[right] = tmp;
	}
	
	public static Integer[] encap(int[] array) {
		Integer[] res = new Integer[array.length];
		for(int i = 0; i < array.length; i++)
			res[i] = array[i];
		return res;
	}
	public static Long[] encap(long[] array) {
		Long[] res = new Long[array.length];
		for(int i = 0; i < array.length; i++)
			res[i] = array[i];
		return res;
	}
	public static Short[] encap(short[] array) {
		Short[] res = new Short[array.length];
		for(int i = 0; i < array.length; i++)
			res[i] = array[i];
		return res;
	}
	public static Character[] encap(char[] array) {
		Character[] res = new Character[array.length];
		for(int i = 0; i < array.length; i++)
			res[i] = array[i];
		return res;
	}
	public static Byte[] encap(byte[] array) {
		Byte[] res = new Byte[array.length];
		for(int i = 0; i < array.length; i++)
			res[i] = array[i];
		return res;
	}
	public static Boolean[] encap(boolean[] array) {
		Boolean[] res = new Boolean[array.length];
		for(int i = 0; i < array.length; i++)
			res[i] = array[i];
		return res;
	}
	public static Float[] encap(float[] array) {
		Float[] res = new Float[array.length];
		for(int i = 0; i < array.length; i++)
			res[i] = array[i];
		return res;
	}
	public static Double[] encap(double[] array) {
		Double[] res = new Double[array.length];
		for(int i = 0; i < array.length; i++)
			res[i] = array[i];
		return res;
	}
	public static int[] decap(Integer[] array) {
		int[] res = new int[array.length];
		for(int i = 0; i < array.length; i++)
			res[i] = array[i];
		return res;
	}
	public static long[] decap(Long[] array) {
		long[] res = new long[array.length];
		for(int i = 0; i < array.length; i++)
			res[i] = array[i];
		return res;
	}
	public static short[] decap(Short[] array) {
		short[] res = new short[array.length];
		for(int i = 0; i < array.length; i++)
			res[i] = array[i];
		return res;
	}
	public static char[] decap(Character[] array) {
		char[] res = new char[array.length];
		for(int i = 0; i < array.length; i++)
			res[i] = array[i];
		return res;
	}
	public static byte[] decap(Byte[] array) {
		byte[] res = new byte[array.length];
		for(int i = 0; i < array.length; i++)
			res[i] = array[i];
		return res;
	}
	public static boolean[] decap(Boolean[] array) {
		boolean[] res = new boolean[array.length];
		for(int i = 0; i < array.length; i++)
			res[i] = array[i];
		return res;
	}
	public static float[] decap(Float[] array) {
		float[] res = new float[array.length];
		for(int i = 0; i < array.length; i++)
			res[i] = array[i];
		return res;
	}
	public static double[] decap(Double[] array) {
		double[] res = new double[array.length];
		for(int i = 0; i < array.length; i++)
			res[i] = array[i];
		return res;
	}
}
